package controller

import (
	"github.com/gin-gonic/gin"
	"niu-video/app/model"
	"niu-video/app/service"
	"niu-video/pkg/response"
	"niu-video/pkg/validate"
)

type RelationController struct {
}

// Relation 关注/取关
func (ctrl *RelationController) Relation(c *gin.Context) {

	request := model.RelationAction{}
	if ok := validate.Validate(c, &request); !ok {
		return
	}
	userId := c.GetInt64("current_user_id")
	msg, err := service.RelationService.Relation(request, userId)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithMessage(msg, c)
}

// Follow 关注的博主视频列表
func (ctrl *RelationController) Follow(c *gin.Context) {
	request := model.PageRequest{}
	if ok := validate.Validate(c, &request); !ok {
		return
	}
	userId := c.GetInt64("current_user_id")
	list, err := service.RelationService.Follow(request, userId)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(list, c)
}
